Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimal support for 4.x #733

Merged
merged 18 commits into from
Oct 27, 2023
Merged

Add minimal support for 4.x #733

merged 18 commits into from
Oct 27, 2023

Conversation

scotttrinh
Copy link
Collaborator

@scotttrinh scotttrinh commented Sep 13, 2023

A few new features have been developed in 4.0 that needed some updates here to get the driver and query builder to work:

  1. multirange which is basically a collection type of ranges.
  2. Full-text search has introduced a new pseudo-type called anyobject which is a subset of anytype.

There was also a change to cardinality inference that made certain polymorphic queries an error condition now, and that has been addressed here as well.

@scotttrinh scotttrinh force-pushed the fix-multirange-anytype branch from 58420a4 to 872bcd2 Compare September 13, 2023 19:43
@bastien8060
Copy link

bastien8060 commented Sep 14, 2023

Would this fix the 'Cannot find 'anytype' in multirangestd::anypoint' error while introspecting the database schema, when generating query builder? (EdgeDB 4.x alpha)

Edit: Currently running into this issue, but I'm guessing the error lies in where the client doesn't support a subset of changes the server has undergone from 3.x to 4.x

@scotttrinh
Copy link
Collaborator Author

@bastien8060

Would this fix the 'Cannot find 'anytype' in multirangestd::anypoint' error while introspecting the database schema, when generating query builder? (EdgeDB 4.x alpha)

That's right: it's been failing for some time now with that message, and I was hoping there would be an easy (yet wrong) workaround for this ahead of actually implementing support, but alas, nothing just fell into my lap yesterday.

Hope to get multirange support for 4.x-alpha in the next few weeks though, stay tuned!

@bastien8060
Copy link

@scotttrinh Awesome! I'll be keeping an eye out :) Currently depending on it, so I'll just revert to the client.query methods for now!

@scotttrinh
Copy link
Collaborator Author

@bastien8060 You're depending on 4.0-alpha?

@bastien8060
Copy link

bastien8060 commented Sep 21, 2023

@scotttrinh Actually sort of, so my application is rather latency critical, and it seems the first query is much faster on 4.0-alpha than on 3.x, but still not quite there imo. And it's funny, but it's not an issue I noticed on the python client. I might submit an issue on the JS client I think—

On the JS client, the first request always takes a couple seconds, regardless of how long the client has been initialized for.

const baseClient = createClient();

const configClient = baseClient.withConfig({
  "session_idle_transaction_timeout": Duration.from({ seconds: 0 }),
});

const client = await configClient.ensureConnected();

Edit: I created #740

@scotttrinh scotttrinh force-pushed the fix-multirange-anytype branch 5 times, most recently from f3d40a4 to e4286f9 Compare October 10, 2023 16:00
@scotttrinh scotttrinh force-pushed the fix-multirange-anytype branch from e4286f9 to 54f0ee3 Compare October 11, 2023 16:31
@scotttrinh scotttrinh force-pushed the fix-multirange-anytype branch from 0038d2f to 5379b1d Compare October 12, 2023 01:02
@scotttrinh scotttrinh changed the title wip Handle multirange in introspection query Add minimal support 4.x Oct 12, 2023
@scotttrinh scotttrinh changed the title Add minimal support 4.x Add minimal support for 4.x Oct 12, 2023
@@ -310,14 +310,15 @@ describe("select", () => {
test("* in polymorphic", async () => {
const q = e.select(e.Person, () => ({
...e.is(e.Hero, e.Hero["*"]),
name: true,
Copy link
Collaborator Author

@scotttrinh scotttrinh Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change reflects the new behavior of 4.x where the parent type's cardinality is considered when using polymorphic queries. In this case, Person has a required name, but the query can return Person records that are not Heros, which would return a empty set name, which is invalid for Person.

@scotttrinh scotttrinh marked this pull request as ready for review October 13, 2023 15:57
@scotttrinh scotttrinh requested a review from jaclarke October 13, 2023 15:57

toJSON() {
return {
ranges: this._ranges,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should probably just return the array, to mirror edgedb's json representation of multiranges.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also probably should copy the array so you can't mutate it. (Or maybe this should be done in the constructor? or both?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I think I just copied this from the python impl, but that makes sense!

throw Error("expected multirange subtype to be scalar type");
}
ctx.imports.add("MultiRange");
return `MultiRange<${subCodec.tsType}>`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have ranges of LocalDate/Time, so we also need to check if the subCodec type needs adding to ctx.imports

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mirrors what we're doing in Range, do you think that's also broken? Looking at how ArrayCodec is done here, maybe I need to wrap this and the Range subcodec in a recursive call to walkCodec?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you're right, Range also looks like it has the same problem. Either walkCodec or since we know the subCodec is going to be a scalar we could just inline the codec.importedType check, both ways seem fine to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll stick with walkCodec just in case other behavior falls out and that seems to match how we're doing other types with subcodecs. Thanks for catching this!

@jaclarke
Copy link
Member

While we're messing with ranges, could we also add this small fix to the range constructor: https://github.com/edgedb/edgedb-js/pull/711/files#diff-96a05a9179de11464b9faa257493af517dcd41f1d1b188b059a748dbd55e463aR29

@jaclarke jaclarke mentioned this pull request Oct 25, 2023
2 tasks
Also defensively copy both on the way in and the way out
It should include the lower bound if `_lower` is not `null` or
`undefined`
@scotttrinh scotttrinh force-pushed the fix-multirange-anytype branch from 52369ee to c0c7210 Compare October 26, 2023 14:12
@scotttrinh scotttrinh requested a review from jaclarke October 26, 2023 14:15
@scotttrinh scotttrinh merged commit 64b5fc9 into master Oct 27, 2023
8 checks passed
@scotttrinh scotttrinh deleted the fix-multirange-anytype branch October 27, 2023 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants